package shapes;

public class StringUtilities {

    public String characterRepeat(int length) {
        StringBuffer outputBuffer = new StringBuffer(length);
        for (int i = 0; i < length; i++){
            outputBuffer.append("*");
        }
        return outputBuffer.toString();
    }

    public String padRight(String s, int n) {
        return String.format("%1$-" + n + "s", s);
    }

    public String padLeft(String s, int n) {
        return String.format("%1$" + n + "s", s);
    }

    public String padCenter(String s, int len) {
        String out = String.format("%"+len+"s%s%"+len+"s", "",s,"");
        float mid = (out.length()/2);
        float start = mid - (len/2);
        float end = start + len;
        return out.substring((int)start, (int)end);
    }
}
